#!/command/with-contenv bashio
# vim: ft=bash
# shellcheck shell=bash
# ==============================================================================
# Start Piper service
# ==============================================================================
flags=()
if [[ "${PIPER_UPDATE_VOICES,,}" =~ ^(true|1|yes)$ ]]; then
    flags+=("--update-voices")
fi

if [[ "${PIPER_DEBUG,,}" =~ ^(true|1|yes)$ ]]; then
    flags+=("--debug")
fi

if [[ "${PIPER_USE_CUDA,,}" =~ ^(true|1|yes)$ ]]; then
    flags+=("--use-cuda")
fi

# shellcheck disable=SC2068
exec python3 -m wyoming_piper \
    --uri "tcp://0.0.0.0:${PIPER_PORT}" \
    --length-scale "${PIPER_LENGTH_SCALE}" \
    --noise-scale "${PIPER_NOISE_SCALE}" \
    --noise-w "${PIPER_NOISE_W}" \
    --speaker "${PIPER_SPEAKER}" \
    --voice "${PIPER_VOICE}" \
    --data-dir "${PIPER_CACHE}" \
    --download-dir "${PIPER_CACHE}" \
    ${flags[@]}
